package oa.hleast.xswl.service.impl;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.xswl.pojo.dto.SmsRequestDto;
import oa.hleast.xswl.service.SmsSendService;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@AllArgsConstructor
public class SmsSendServiceImpl implements SmsSendService {
    public static final String ALIYUN_SMS_DOMAIN = "dysmsapi.aliyuncs.com";
    public static final String ALIYUN_REGION_ID = "cn-hangzhou";
    public static final String ALIYUN_SYS_VERSION = "2017-05-25";
    public static final String ALIYUN_SYS_ACTION_SEND_SMS = "SendSms";

    private final IAcsClient iAcsClient;

//    StringRedisTemplate stringRedisTemplate;
//    @Autowired
//    private SmsRecordRepo smsRecordRepo;

    @Override
    public void sendSms(SmsRequestDto smsRequest) {
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain(ALIYUN_SMS_DOMAIN);
        request.setSysVersion(ALIYUN_SYS_VERSION);
        request.setSysAction(ALIYUN_SYS_ACTION_SEND_SMS);
        request.putQueryParameter("RegionId", ALIYUN_REGION_ID);
        request.putQueryParameter("PhoneNumbers", smsRequest.getTo());
        request.putQueryParameter("SignName", "信网真");
        request.putQueryParameter("TemplateCode", smsRequest.getTemplateCode());
        request.putQueryParameter("TemplateParam", smsRequest.getTemplateParam());
        try {
            CommonResponse response = iAcsClient.getCommonResponse(request);
            log.info("response = {}", response);
            String data = response.getData();
            ObjectMapper mapper = new ObjectMapper();
        } catch (ClientException e) {
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("get 1111111");
            e.printStackTrace();
        }
    }


}
